Skip to content

Stan/buffer fix#81

Merged
sczembor merged 5 commits intomasterfrom
stan/buffer-fix
Sep 18, 2025
Merged

Stan/buffer fix#81
sczembor merged 5 commits intomasterfrom
stan/buffer-fix

Conversation

@sczembor
Copy link
Contributor

@sczembor sczembor commented Sep 18, 2025

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • added appropriate labels to the PR
  • provided a link to the relevant issue or specification
  • added a changelog entry to CHANGELOG.md
  • included doc comments for public functions
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary

Summary by Sourcery

Fix buffer handling in block retrieval and clean up formatting of SQL queries and function arguments

Bug Fixes:

  • Fetch raw block data as an arrayBuffer and parse via Buffer.from, logging a warning and skipping processing when block data is missing

Enhancements:

  • Remove trailing commas in SQL query strings and function call arguments for consistent formatting

Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
@sczembor sczembor requested a review from a team as a code owner September 18, 2025 13:45
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 18, 2025

Reviewer's Guide

This PR updates block retrieval to fetch raw block data as an ArrayBuffer (with a warning if missing) and converts it to a Buffer for Block.fromBuffer, replacing the previous hex-based approach. It also standardizes code formatting by removing trailing commas and unifying SQL and logging string formatting throughout the indexer.

Sequence diagram for updated block retrieval and processing in processFinalizedTransactions

sequenceDiagram
    participant Indexer
    participant blocksDB
    participant Block
    participant MerkleTree
    Indexer->>blocksDB: get(block_hash, { type: "arrayBuffer" })
    blocksDB-->>Indexer: rawBlockBuffer
    alt Block data found
        Indexer->>Block: fromBuffer(Buffer.from(rawBlockBuffer))
        Block-->>Indexer: block
        Indexer->>MerkleTree: constructMerkleTree(block)
        MerkleTree-->>Indexer: merkleTree
    else Block data missing
        Indexer->>Indexer: log warning and skip TX
    end
Loading

Class diagram for updated Block instantiation in Indexer

classDiagram
    class Indexer {
        +processFinalizedTransactions()
        +blocksDB: BlocksDB
    }
    class BlocksDB {
        +get(key, options)
    }
    class Block {
        +fromBuffer(buffer)
        +fromHex(hex)
    }
    Indexer --> BlocksDB : uses
    Indexer --> Block : instantiates
    note for Block "fromBuffer(buffer) is now used instead of fromHex(hex)"
Loading

File-Level Changes

Change Details Files
Block data retrieval switched from hex to binary buffer with missing-data warning
  • Use blocksDB.get(key, { type: 'arrayBuffer' }) to fetch raw block data
  • Check for missing block data, log a warning, and skip the transaction
  • Convert the returned ArrayBuffer to a Node Buffer and call Block.fromBuffer
  • Remove the old Block.fromHex path
packages/btcindexer/src/btcindexer.ts
Cleanup of trailing commas and formatting in SQL, logs, and parameter lists
  • Removed trailing commas from method calls and argument lists
  • Unified backtick formatting in SQL queries and console.log statements
  • Adjusted .bind calls to eliminate extraneous commas
packages/btcindexer/src/btcindexer.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • You’re injecting the now timestamp directly into multiple SQL statements, which prevents statement caching and forces a new prepare on each run — consider using bound parameters instead so the prepared statements can be reused.
  • Instead of console.log/console.warn, consider adopting a structured logging framework or a centralized logger to standardize log levels and output formats.
  • When block data is missing from your KV store you simply warn and skip the transaction, which could leave it stuck; consider adding retry logic or marking it as failed after a threshold of missing attempts.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- You’re injecting the `now` timestamp directly into multiple SQL statements, which prevents statement caching and forces a new prepare on each run — consider using bound parameters instead so the prepared statements can be reused.
- Instead of console.log/console.warn, consider adopting a structured logging framework or a centralized logger to standardize log levels and output formats.
- When block data is missing from your KV store you simply warn and skip the transaction, which could leave it stuck; consider adding retry logic or marking it as failed after a threshold of missing attempts.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
@sczembor sczembor self-assigned this Sep 18, 2025
@sczembor sczembor merged commit c82c789 into master Sep 18, 2025
12 checks passed
@sczembor sczembor deleted the stan/buffer-fix branch September 18, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants